#include "checkpoint.h"

//重写绘图事件
void Checkpoint::paintEvent(QPaintEvent *)
{
    pMap->begin(this);
    pBox->drawMap(pMap);
    if(pBox->gameOver())
    {
        QTimer::singleShot(1000,this,[=]{
            //发送点击返回按钮的信号
            emit this->ChooseSceneBack();
        });
    }
    pMap->end();
    update();
}

//重写键盘事件
void Checkpoint::keyPressEvent(QKeyEvent *event)
{
    pBox->keyDown(event);
}


//构造函数，关卡初始化
Checkpoint::Checkpoint(int Index)
{
    levelIndex = Index;

    //设置窗口尺寸
    this->setFixedSize(900,900);
    //设置窗口标题
    char c =  Index+48;
    QString str = QString("推箱子 第%1关").arg(c);
    this->setWindowTitle(str);
    //设置窗口图标
    this->setWindowIcon(QIcon(":/res/1.png"));
    //创建画家对象
    pMap = new QPainter(this);
    //创建Qboxman对象
    pBox = new QBoxMan(Index);
    //创建菜单栏
    QMenuBar *bar = menuBar();
    QMenu *startMenu = bar->addMenu("Menu");
    QAction *backAction = startMenu->addAction("ChooseLevel");
    connect(backAction, &QAction::triggered,[=]{
        QTimer::singleShot(0,this,[=]{
            //发送点击返回按钮的信号
            emit this->ChooseSceneBack();
        });
    });
}
